﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ClientRegister
{
    public partial class EmployeeRegisForm : Form
    {
        public string ID { set; get; }
        public string Password { set; get; }
        public string Name { set; get; }

        StudentDataProvider loadStu = new StudentDataProvider();
        ClassInCourseProvider loadClass = new ClassInCourseProvider();

        public EmployeeRegisForm()
        {
            InitializeComponent();
        }
        // Form Load
        private void NhanvienDK_Load(object sender, EventArgs e)
        {
            CourseDataProvider loadCour = new CourseDataProvider();
            cbboxCourse.DataSource = loadCour.loadCourses().Tables[0];
            cbboxCourse.DisplayMember = "NameCourse";
            cbboxCourse.ValueMember = "ID";
        }
    //Đổi mật khẩu
        private void đổiMậtKhẩuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChangePasswordForm dmkform = new ChangePasswordForm();
            dmkform.ID = ID;
            dmkform.Password = Password;
            dmkform.Show();
        }
        //Thoát hệ thống
        private void thoátToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        //Đăng ký học viên mới
        //Đăng ký theo khóa
        private void đăngKýTheoKhóaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            newStudentRegisterCourseForm regCourse = new newStudentRegisterCourseForm();
            regCourse.Show();
        }
        //Đăng ký theo lớp
        private void đăngKýTheoLớpHọcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            newStudentRegisterClassForm regClass = new newStudentRegisterClassForm();
            regClass.Show();
        }
        //Đăng ký học viên cũ
        private void đăngKýHọcViênCũToolStripMenuItem_Click(object sender, EventArgs e)
        {
            oldStudentRegisterForm oldregis = new oldStudentRegisterForm();
            oldregis.Show();
        }
        
        //Chinh sua thong tin ca nhan cua hoc vien
        private void thôngTinCáToolStripMenuItem_Click(object sender, EventArgs e)
        {

            ListStudentForm edit = new ListStudentForm();
            edit.IDEmp = ID;
            edit.NameEmp = Name;
            edit.Show();
        }
        // Chinh sua thong tin Khoa hoc/Lop hoc cua hoc vien
        private void thôngTinLớpHọcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CourseAndClassOfStudentForm ccs = new CourseAndClassOfStudentForm();
            ccs.IDEmp = ID;
            ccs.NameEmp = Name;
            ccs.Show();
        }

        private void thôngTinToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StudentInfoDetailForm viewDetail = new StudentInfoDetailForm();
            viewDetail.Show();
        }

        private void cbboxCourse_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbboxCourse.SelectedValue.ToString() == "System.Data.DataRowView")
                return;
            else
            {
                cbboxClasses.DataSource = loadClass.loadClassOfCourse(cbboxCourse.SelectedValue.ToString()).Tables[0];
                cbboxClasses.DisplayMember = "NameClass";
                cbboxClasses.ValueMember = "ID";

                gridListStu.DataSource = loadStu.loadStudentInCourse(cbboxCourse.SelectedValue.ToString()).Tables[0];
            }
        }

        private void cbboxClasses_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbboxClasses.SelectedValue.ToString() == "System.Data.DataRowView")
                return;
            else
            {
                gridListStu.DataSource = loadStu.loadStudentInClass(cbboxClasses.SelectedValue.ToString(), cbboxCourse.SelectedValue.ToString()).Tables[0];
            }
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            gridListStu.DataSource = loadStu.loadStudentInCourse(cbboxCourse.SelectedValue.ToString()).Tables[0];
        }
    }
}
